home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 2.6 KB | 114 lines | [TEXT/MPS ] |
- // The C++ Booch Components (Version 2.1)
- // (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
- //
- // BCColl.h
- //
- // This file contains the declaration of the collection abstract base class
- // and its iterators.
-
- #ifndef BCCOLL_H
- #define BCCOLL_H 1
-
- #include "BCType.h"
-
- template<class Item>
- class BC_TCollectionActiveIterator;
-
- template<class Item>
- class BC_TCollectionPassiveIterator;
-
- template<class Item, class Structure>
- class BC_TPersist;
-
- // Collection abstract base class
-
- template<class Item>
- class BC_TCollection {
- public:
-
- BC_TCollection();
- BC_TCollection(const BC_TCollection<Item>&);
- virtual ~BC_TCollection();
-
- virtual BC_TCollection<Item>& operator=(const BC_TCollection<Item>&);
- virtual BC_Boolean operator==(const BC_TCollection<Item>&) const;
- BC_Boolean operator!=(const BC_TCollection<Item>&) const;
- virtual const Item& operator[](BC_Index) const = 0;
- virtual Item& operator[](BC_Index) = 0;
-
- virtual void Clear() = 0;
- virtual void Insert(const Item&) = 0;
- virtual void Insert(const Item&, BC_Index before) = 0;
- virtual void Append(const Item&) = 0;
- virtual void Append(const Item&, BC_Index after) = 0;
- virtual void Remove(BC_Index at) = 0;
- virtual void Replace(BC_Index at, const Item&) = 0;
-
- virtual BC_Index Length() const = 0;
- virtual BC_Boolean IsEmpty() const = 0;
- virtual const Item& First() const = 0;
- virtual Item& First() = 0;
- virtual const Item& Last() const = 0;
- virtual Item& Last() = 0;
- virtual BC_ExtendedIndex Location(const Item&) const = 0;
-
- protected:
-
- virtual void Purge() = 0;
- virtual void Add(const Item&) = 0;
- virtual BC_Index Cardinality() const = 0;
- virtual const Item& ItemAt(BC_Index) const = 0;
-
- virtual void Lock();
- virtual void Unlock();
-
- private:
-
- friend class BC_TCollectionActiveIterator<Item>;
- friend class BC_TCollectionPassiveIterator<Item>;
-
- friend class BC_TPersist<Item, BC_TCollection<Item> >;
-
- };
-
- // Collection iterators
-
- template <class Item>
- class BC_TCollectionActiveIterator {
- public:
-
- BC_TCollectionActiveIterator(const BC_TCollection<Item>&);
- ~BC_TCollectionActiveIterator();
-
- void Reset();
- BC_Boolean Next();
-
- BC_Boolean IsDone() const;
- const Item* CurrentItem() const;
- Item* CurrentItem();
-
- protected:
-
- const BC_TCollection<Item>& fCollection;
- BC_ExtendedIndex fIndex;
-
- };
-
- template <class Item>
- class BC_TCollectionPassiveIterator {
- public:
-
- BC_TCollectionPassiveIterator(const BC_TCollection<Item>&);
- ~BC_TCollectionPassiveIterator();
-
- BC_Boolean Apply(BC_Boolean (*)(const Item&));
- BC_Boolean Apply(BC_Boolean (*)(Item&));
-
- protected:
-
- const BC_TCollection<Item>& fCollection;
-
- };
-
- #endif
-